#!/bin/bash
#********************************************************************
#Author: Andy
#Date： 2021-03-24
#FileName： docker-install.sh
#URL： 
#Description： docker-20离线安装脚本
#********************************************************************
echo -e "\033[41;37m本机信息如下:\033[0m"
cat /proc/version
lsb_release -a 
currentIP=`ifconfig | grep broadcast | awk "NR==3" | awk -F" " '{print $2}'`
echo $currentIP
echo ""

read -p "是否继续安装y/N: " continueinstall
if [ $continueinstall == "N" ] ; then  
  exit 0;
fi
echo -e "\033[41;37m开始安装Docker...........\033[0m"

read -p "是否开始安装docker服务y/N: " dockerinstall
if [ $dockerinstall == "y" ] ; then  
	echo "关闭SWAP......"
	swapoff -a
	rm -f /swap.img
	sed -i "s/\/swap.img/#\/swap.img/g" /etc/fstab

	echo "开启IP转发"
	sed -i "s/#net.ipv4.ip_forward/net.ipv4.ip_forward/g" /etc/sysctl.conf
	sysctl -p

	echo "开始更新系统..........."
	sudo apt-get update
	sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common
	curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
	sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
	sudo apt-get -y update
	echo "开始安装docker..........."
	sudo apt-get install -y docker-ce
	systemctl enable docker

	echo "开始安装docker-compose..........."
	apt-get install -y docker-compose
	echo ""
	echo -e "\033[41;37mdocker及docker-compose安装完成，信息如下:\033[0m"
	docker version
	docker-compose version
fi

echo ""
echo -e "\033[41;37m开始安装软件，可安装软件有:\033[0m"
echo -e "\033[41;37m......portainer......\033[0m"
echo -e "\033[41;37m......mongodb......\033[0m"
echo -e "\033[41;37m......redis......\033[0m"
echo -e "\033[41;37m......mysql......\033[0m"
echo -e "\033[41;37m......nacos......\033[0m"
echo -e "\033[41;37m......torna......\033[0m"
echo -e "\033[41;37m......nexus......\033[0m"
echo -e "\033[41;37m......ldap......\033[0m"
echo -e "\033[41;37m......skywalking......\033[0m"
echo -e "\033[41;37m......rocketmq......\033[0m"

# 部署portainer
read -p "是否安装并启动portainer服务y/N: " portainer
if [ $portainer == "y" ] ; then 
  PORTAINER_CONTAINER_NAME=base-portainer
  PORTAINER_PORT=49000
  PORTAINER_HOME=/software/docker/portainer
  docker rm -f $PORTAINER_CONTAINER_NAME
  rm -rf $PORTAINER_HOME
  mkdir -p $PORTAINER_HOME/{data,public}
  cd $PORTAINER_HOME/public
  git clone https://gitee.com/yos/portainer-cn.git
  cp -rf portainer-cn/* ./
  rm -rf portainer-cn/
  #unzip -o Portainer-CN.zip -d $PORTAINER_HOME/public/
  chown -R andy:andy $PORTAINER_HOME
  echo "正在启动portainer.........."
  docker run -d --restart=always --name $PORTAINER_CONTAINER_NAME -p $PORTAINER_PORT:9000 -v /var/run/docker.sock:/var/run/docker.sock -v $PORTAINER_HOME/data:/data -v $PORTAINER_HOME/public:/public portainer/portainer:latest
  echo "\033[41;37mportainer启动完成，请通过: "$currentIP:$PORTAINER_PORT"访问\033[0m"
fi

# 部署mongodb
read -p "是否安装并启动mongodb服务y/N: " mongodb
if [ $mongodb == "y" ] ; then 
  echo "安装参考：https://www.cnblogs.com/smiler/p/10112676.html"
  MONGO_CONTAINER_NAME=base-mongodb
  MONGO_HOME=/software/docker/mongodb
  MONGO_PORT=47017
  docker rm -f $MONGO_CONTAINER_NAME
  rm -rf $MONGO_HOME
  mkdir -p $MONGO_HOME/{data}
  chown -R andy:andy $MONGO_HOME
  echo "正在启动MongoDB.............."  
  docker run -d --restart=always --name $MONGO_CONTAINER_NAME -p $MONGO_PORT:27017 -v $MONGO_HOME/data:/data/db mongo:latest --auth
  echo -e "\033[41;37mMongo启动完成，请通过: "$currentIP:$MONGO_PORT"访问\033[0m"
  echo "创建用户"
  echo "docker exec -it $MONGO_CONTAINER_NAME /bin/bash"
  echo "mongo"
  echo "use admin"
  echo 'db.createUser({user:"root",pwd:"123456",roles:[{role:'root',db:'admin'}]})'
  docker ps
fi

# 部署Redis
read -p "是否安装并启动Redis服务y/N: " redis
if [ $redis == "y" ] ; then 
  echo "安装参考：https://www.cnblogs.com/marshhu/p/12636536.html"
  REDIS_CONTAINER_NAME=base-redis
  REDIS_HOME=/software/docker/redis
  REDIS_PORT=46379  
  docker rm -f $REDIS_CONTAINER_NAME
  rm -rf $REDIS_HOME
  mkdir -p $REDIS_HOME/{data,conf}
  
cat > $REDIS_HOME/conf/redis.conf << EOF
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir ./
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass 123456
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
EOF
  chown -R andy:andy $REDIS_HOME
  echo "正在启动Redis.............."  
  docker run -d --restart=always --name $REDIS_CONTAINER_NAME -p $REDIS_PORT:6379 -v $REDIS_HOME/data:/data -v $REDIS_HOME/conf/redis.conf:/etc/redis/redis.conf redis:latest --appendonly yes --requirepass "123456"
  echo -e "\033[41;37mRedis启动完成，请通过: "$currentIP:$REDIS_PORT"访问\033[0m"
  docker ps
fi

# 部署MySQL
read -p "是否安装并启动mysql服务y/N: " mysql
if [ $mysql == "y" ] ; then 
  MYSQL_CONTAINER_NAME=base-mysql
  MYSQL_HOME=/software/docker/mysql
  MYSQL_PORT=43306
  MYSQL_ROOTPWD=1qaz@WSX3edc
  docker rm -f $MYSQL_CONTAINER_NAME
  rm -rf $MYSQL_HOME
  mkdir -p $MYSQL_HOME/{conf,logs,data}
  chown -R andy:andy $MYSQL_HOME
  echo "正在启动MySQL.............."
  docker run -d --restart=always --name $MYSQL_CONTAINER_NAME -p $MYSQL_PORT:3306 -v $MYSQL_HOME/logs:/var/log/mysql -v $MYSQL_HOME/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=$MYSQL_ROOTPWD mysql:latest
  echo -e "\033[41;37mMySQL启动完成，请通过: "$currentIP:$MYSQL_PORT"访问\033[0m"
  docker ps
fi

# 部署OmniDB
read -p "是否安装并启动OmniDB服务y/N: " omnidb
if [ $omnidb == "y" ] ; then 
  OMNIDB_CONTAINER_NAME=base-omnidb
  OMNIDB_HOME=/software/docker/omnidb
  OMNIDB_PORT1=48090

  docker rm -f $OMNIDB_CONTAINER_NAME
  rm -rf $OMNIDB_HOME
  mkdir -p $OMNIDB_HOME/{conf,logs,data}
  chown -R andy:andy $OMNIDB_HOME
  chmod -R 777 $OMNIDB_HOME

  echo "正在启动OmniDB.............."
  docker run -d --restart=always --name $OMNIDB_CONTAINER_NAME -p $currentIP:$OMNIDB_PORT1:8080 -p $currentIP:25482:25482 -v $OMNIDB_HOME/conf:/etc/omnidb taivokasper/omnidb
  echo -e "\033[41;37OmniDB启动完成，请通过: "$currentIP:$OMNIDB_PORT1"访问\033[0m"
  docker ps
fi

# 部署Torna
read -p "是否安装并启动torna服务y/N: " torna
if [ $torna == "y" ] ; then 
  TORNA_CONTAINER_NAME=base-torna
  TORNA_HOME=/software/docker/torna
  TORNA_PORT=47700
  docker rm -f $TORNA_CONTAINER_NAME
  rm -rf $TORNA_HOME
  mkdir -p $TORNA_HOME/{conf,logs}
cat > $TORNA_HOME/conf/application.properties << EOF
server.port=7700
mysql.host=mysql:3306
mysql.schema=torna
mysql.username=root
mysql.password=1qaz@WSX3edc
EOF
  chown -R andy:andy $TORNA_HOME
  echo "正在启动Torna.............."
  docker run -d --restart=always --name $TORNA_CONTAINER_NAME -p $TORNA_PORT:7700 --link=base-mysql:mysql -v $TORNA_HOME/conf:/torna/config tanghc2020/torna:latest
  echo -e "\033[41;37mTorna启动完成，请通过: "$currentIP:$TORNA_PORT"访问,默认用户名密码为：admin@torna.cn/123456\033[0m"
  docker ps
fi

# 部署Nacos
read -p "是否安装并启动nacos服务y/N: " nacos
if [ $nacos == "y" ] ; then 
  echo "安装参考：https://blog.csdn.net/qq_42021376/article/details/116035237?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-8.no_search_link"
  NACOS_CONTAINER_NAME=base-nacos
  NACOS_HOME=/software/docker/nacos
  NACOS_PORT=48848
  docker rm -f $NACOS_CONTAINER_NAME
  rm -rf $NACOS_HOME
  mkdir -p $NACOS_HOME/{logs,conf,data}
cat > $NACOS_HOME/conf/application.properties << "EOF"
# spring
server.servlet.contextPath=/nacos
server.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=1
db.url.0=jdbc:mysql://mysql:3306/nacos?serverTimezone=UTC&characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
db.user=root
db.password=1qaz@WSX3edc
nacos.core.auth.system.type=nacos
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=true
nacos.core.auth.server.identity.key=
nacos.core.auth.server.identity.value=
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
server.tomcat.basedir=
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
EOF
  chown -R andy:andy $NACOS_HOME
  echo "正在启动Nacos.............."
  docker run -d --restart=always --name $NACOS_CONTAINER_NAME -p $NACOS_PORT:8848 --link=base-mysql:mysql --privileged=true -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -v $NACOS_HOME/logs:/home/nacos/logs -v $NACOS_HOME/data:/home/nacos/data -v $NACOS_HOME/conf/application.properties:/home/nacos/conf/application.properties nacos/nacos-server
  echo -e "\033[41;37m完成Nacos启动，请通过: "$currentIP:$NACOS_PORT"访问,默认用户名密码：nacos/nacos\033[0m"  
fi

# 部署Nexus
read -p "是否安装并启动nexus服务y/N: " nexus
if [ $nexus == "y" ] ; then   
  NEXUS_CONTAINER_NAME=base-nexus
  NEXUS_HOME=/software/docker/nexus
  NEXUS_PORT1=48081
  NEXUS_PORT2=48082
  NEXUS_PORT3=48083
  NEXUS_PORT4=48084
  docker rm -f $NEXUS_CONTAINER_NAME
  rm -rf $NEXUS_HOME
  mkdir -p $NEXUS_HOME/{conf,logs,data}
  chown -R andy:andy $NEXUS_HOME
  chmod 777 $NEXUS_HOME/data/
  echo "正在启动Nexus.............."
  docker run -d --restart=always --name $NEXUS_CONTAINER_NAME -p $NEXUS_PORT1:8081 -p $NEXUS_PORT2:8082 -p $NEXUS_PORT3:8083 -p $NEXUS_PORT4:8084 --privileged=true -v $NEXUS_HOME/data:/nexus-data sonatype/nexus3  
  echo -e "\033[41;37mNexus启动完成，请通过: "$currentIP:$NEXUS_PORT1"访问\033[0m"
  echo -e "\033[41;37m默认账号:cat $NEXUS_HOME/data/admin.password查看\033[0m"
  docker ps
fi

# 部署LDAP
read -p "是否安装并启动LDAP服务y/N: " ldap
if [ $ldap == "y" ] ; then 
  LDAP_CONTAINER_NAME=base-ldap
  LDAP_HOME=/software/docker/ldap
  LDAP_PORT1=389
  LDAP_PORT2=636
  docker rm -f $LDAP_CONTAINER_NAME
  rm -f $LDAP_HOME
  LDAPADM_CONTAINER_NAME=base-ldapadmin
  LDAPADM_HOME=/software/docker/ldapadm
  LDAPADM_PORT=48080
  docker rm -f $LDAPADM_CONTAINER_NAME
  rm -f $LDAPADM_HOME
  mkdir -p $LDAP_HOME/{conf,logs,data}
  chown -R andy:andy $LDAP_HOME
  mkdir -p $LDAPADM_HOME/{conf,logs,data}
  chown -R andy:andy $LDAPADM_HOME
  echo "正在启动LDAP.............."
  docker run -d --restart=always --name $LDAP_CONTAINER_NAME -p $LDAP_PORT1:389 -p $LDAP_PORT2:636 --network bridge --hostname openldap-host --env LDAP_ORGANISATION="andy" --env LDAP_DOMAIN="andy.com" --env LDAP_ADMIN_PASSWORD="123456" --detach osixia/openldap
  docker run -d --restart=always --name $LDAPADM_CONTAINER_NAME --privileged -p 58080:80 --env PHPLDAPADMIN_HTTPS=false --env PHPLDAPADMIN_LDAP_HOSTS=192.168.43.90 --detach osixia/phpldapadmin
  echo -e "\033[41;37mNexus启动完成，请通过: "$currentIP:$LDAPADM_PORT"访问，用户名密码是：cn=admin,dc=andy,dc=com/123456\033[0m"
  docker ps
fi

# 部署SkyWalking
read -p "是否安装并启动skywalking服务y/N: " skywalking
if [ $skywalking == "y" ] ; then 
  echo "参考：https://blog.csdn.net/hello123yy/article/details/114637432"
  SKYWALK_CONTAINER_NAME=base-skywalking
  SKYWALKUI_CONTAINER_NAME=base-skywalking-ui
  SKYWALK_HOME=/software/docker/skywalking
  SKYWALK_PORT1=41234
  SKYWALK_PORT2=41800
  SKYWALK_PORT3=42800
  SKYWALK_PORT4=48088
  docker rm -f $SKYWALK_CONTAINER_NAME
  docker rm -f $SKYWALKUI_CONTAINER_NAME
  rm -f $SKYWALK_HOME
  mkdir -p $SKYWALK_HOME/{conf,logs,data,libs}
  cp mysql-connector-java-8.0.17.jar $SKYWALK_HOME/libs/
  chown -R andy:andy $SKYWALK_HOME
  chmod 666 -R $SKYWALK_HOME/*

  echo "正在启动skywalking.............."  
  docker run -d --restart=always --name base-skywalking-server -p $SKYWALK_PORT1:1234 -p $41800:11800 -p $42800:12800 --link=base-mysql:mysql -e SW_STORAGE=mysql -e SW_JDBC_URL="jdbc:mysql://mysql:53306/skywalking?useSSL=false" -e SW_DATA_SOURCE_USER=root -e SW_DATA_SOURCE_PASSWORD=1qaz@WSX3edc-e SW_DATA_SOURCE_CACHE_PREP_STMTS="true" -e SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE=250 -e SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT=2048 -e SW_DATA_SOURCE_USE_SERVER_PREP_STMTS="true" -e SW_STORAGE_MYSQL_QUERY_MAX_SIZE=5000 -v /software/docker/skywalking/libs/mysql-connector-java-8.0.17.jar:/skywalking/oap-libs/mysql-connector-java-8.0.17.jar apache/skywalking-oap-server
  docker run -d --restart=always --name base-skywalking-ui -p $SKYWALK_PORT4:8080 -e SW_OAP_ADDRESS=base-skywalking-server:$SKYWALK_PORT3 apache/skywalking-ui
  echo -e "\033[41;37mSkyWalking启动完成，请通过: "$currentIP:$SKYWALK_PORT4"访问\033[0m"
  
  docker run -d --restart=always --name base-skywalking-server -p 41234:1234 -p 41800:11800 -p 42800:12800 --link=base-mysql:mysql -e SW_STORAGE=mysql -e SW_JDBC_URL="jdbc:mysql://mysql:53306/skywalking?useSSL=false" -e SW_DATA_SOURCE_USER=root -e SW_DATA_SOURCE_PASSWORD=1qaz@WSX3edc-e SW_DATA_SOURCE_CACHE_PREP_STMTS="true" -e SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_SIZE=250 -e SW_DATA_SOURCE_PREP_STMT_CACHE_SQL_LIMIT=2048 -e SW_DATA_SOURCE_USE_SERVER_PREP_STMTS="true" -e SW_STORAGE_MYSQL_QUERY_MAX_SIZE=5000 -v /software/docker/skywalking/libs/mysql-connector-java-8.0.17.jar:/skywalking/oap-libs/mysql-connector-java-8.0.17.jar apache/skywalking-oap-server

  docker run -d --restart=always --name base-skywalking-ui -p 48088:8080 -e SW_OAP_ADDRESS=base-skywalking-server:42800 apache/skywalking-ui
  echo -e "\033[41;37mSkyWalking启动完成，请通过: "$currentIP:$SKYWALK_PORT1"访问\033[0m"
  docker ps
fi

# 部署RocketMQ
read -p "是否安装并启动RocketMQ服务y/N: " rocketmq
if [ $rocketmq == "y" ] ; then 
  ROCKETMQ_CONTAINER_NAME=base-rmq-server
  ROCKETMQ_CONTAINER_NAME_BROKER=base-rmq-broker
  ROCKETMQ_CONTAINER_NAME_CONSOLE=base-rmq-console
  ROCKETMQ_HOME=/software/docker/rocketmq
  ROCKETMQ_PORT1=49876
  # ROCKETMQ_PORT2=10909
  # ROCKETMQ_PORT3=10911
  # ROCKETMQ_PORT4=10912
  ROCKETMQ_PORT5=48180
  docker rm -f $ROCKETMQ_CONTAINER_NAME
  docker rm -f $ROCKETMQ_CONTAINER_NAME_CONSOLE
  docker rm -f $ROCKETMQ_CONTAINER_NAME_BROKER
  rm -rf $ROCKETMQ_HOME

  mkdir -p $ROCKETMQ_HOME/namesrv/{conf,logs,store}
  mkdir -p $ROCKETMQ_HOME/broker/{conf,logs,store}
cat > $ROCKETMQ_HOME/broker/conf/broker.conf << EOF
# 所属集群名字
brokerClusterName=Test-Cluster
# broker 名字，注意此处不同的配置文件填写的不一样，如果在 broker-a.properties 使用: broker-a,
# 在 broker-b.properties 使用: broker-b
brokerName=broker-a
# 0 表示 Master，> 0 表示 Slave
brokerId=0
# nameServer地址，分号分割
# namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
# 启动IP,如果 docker 报 com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <192.168.0.120:10909> failed
# 解决方式1 加上一句 producer.setVipChannelEnabled(false);，解决方式2 brokerIP1 设置宿主机IP，不要使用docker 内部IP
brokerIP1=$currentIP
# 在发送消息时，自动创建服务器不存在的topic，默认创建的队列数
defaultTopicQueueNums=4
# 是否允许 Broker 自动创建 Topic，建议线下开启，线上关闭 
autoCreateTopicEnable=true
# 是否允许 Broker 自动创建订阅组，建议线下开启，线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点，默认凌晨4点
deleteWhen=04
# 文件保留时间，默认48小时
fileReservedTime=120
# commitLog 每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue 每个文件默认存 30W 条，根据业务情况调整
mapedFileSizeConsumeQueue=300000
# destroyMapedFileIntervalForcibly=120000
# redeleteHangedFileInterval=120000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 存储路径
# storePathRootDir=/home/ztztdata/rocketmq-all-4.1.0-incubating/store
# commitLog 存储路径
# storePathCommitLog=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/commitlog
# 消费队列存储
# storePathConsumeQueue=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/consumequeue
# 消息索引存储路径
# storePathIndex=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/index
# checkpoint 文件存储路径
# storeCheckpoint=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/checkpoint
# abort 文件存储路径
# abortFile=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/abort
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker 的角色
# - ASYNC_MASTER 异步复制Master
# - SYNC_MASTER 同步双写Master
# - SLAVE
brokerRole=ASYNC_MASTER
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128
EOF
  
  chown -R andy:andy $ROCKETMQ_HOME
  chmod 777 -R $ROCKETMQ_HOME/*
  
  echo "正在启动RocketMQ.............."
  docker run -d --restart=always --name $ROCKETMQ_CONTAINER_NAME -p $ROCKETMQ_PORT1:9876 -v $ROCKETMQ_HOME/namesrv/logs:/home/rocketmq/logs -v $ROCKETMQ_HOME/namesrv/store:/home/rocketmq/store -e "JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m" --privileged=true foxiswho/rocketmq:4.8.0 sh mqnamesrv
  docker run -d --restart=always --name $ROCKETMQ_CONTAINER_NAME_BROKER -p 10911:10911 -p 10912:10912 -p 10909:10909 --link $ROCKETMQ_CONTAINER_NAME:rmqserver -v $ROCKETMQ_HOME/broker/logs:/home/rocketmq/logs -v $ROCKETMQ_HOME/broker/store:/home/rocketmq/store -v $ROCKETMQ_HOME/broker/conf/broker.conf:/etc/rocketmq/broker.conf -e "NAMESRV_ADDR=rmqserver:9876" -e "JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512M -Xmx512M -Xmn128m" --privileged=true foxiswho/rocketmq:4.8.0 sh mqbroker -c "/etc/rocketmq/broker.conf"
  docker run -d --restart=always --name $ROCKETMQ_CONTAINER_NAME_CONSOLE -p $ROCKETMQ_PORT5:8080 --link $ROCKETMQ_CONTAINER_NAME:rmqserver -e "JAVA_OPTS=-Drocketmq.namesrv.addr=rmqserver:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Duser.timezone='Asia/Shanghai'" -t styletang/rocketmq-console-ng
  echo -e "\033[41;37mRocketMQ启动完成，请通过: "$currentIP:$ROCKETMQ_PORT5"访问\033[0m"
  docker ps
fi

# 部署postgres
read -p "是否启动postgres服务y/N: " postgres
if [ $postgres == "y" ] ; then 
  POSTGRES_HOME=/software/docker/postgres
  POSTGRES_CONTAINER_NAME=base-postgres
  POSTGRES_PORT=45432

  docker rm -f $POSTGRES_CONTAINER_NAME
  rm -rf $POSTGRES_HOME
  mkdir -p $POSTGRES_HOME/data
  chmod 666 -R $POSTGRES_HOME/data

  echo "正在启动Postgre.............."  
  docker run -d --restart=always --name $POSTGRES_CONTAINER_NAME -v $POSTGRES_HOME/data:/var/lib/postgresql/data -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=12345678 -p $POSTGRES_PORT:5432 postgres
  
  echo -e "\033[41;37mpostgres启动完成，请通过: "$currentIP:$POSTGRES_PORT"访问，默认用户名密码是：postgres/12345678\033[0m"
  docker ps
fi

# 部署Gotty
read -p "是否启动gotty服务y/N: " gotty
if [ $gotty == "y" ] ; then 
  GOTTY_HOME=/software/docker/gotty
  GOTTY_CONTAINER_NAME=base-gotty
  GOTTY_PORT=48989

  docker rm -f $GOTTY_HOME
  rm -rf $GOTTY_CONTAINER_NAME
  mkdir -p $GOTTY_HOME/data

  echo "正在启动Gotty.............."    
  docker run -p 48989:8080 -d --name base-gotty -it  modenaf360/gotty-docker:latest
  echo -e "\033[41;37mGotty启动完成，请通过: "$currentIP:$GOTTY_PORT"访问\033[0m"
  docker ps
fi

exit 0
